package com.bawei.module_my;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bawei.library_base.RouterPath;
import com.bawei.library_base.mvp.v.BaseFragment;
import com.bawei.library_base.utils.GlideUtil;
import com.bawei.module_my.myorder.MyOrderActivity;
import com.bawei.module_my.nopay.NoPayActivity;
import com.bawei.module_my.pj.PjActivity;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import de.hdodenhof.circleimageview.CircleImageView;


@Route(path = RouterPath.My.PAGER_MY)
public class MyFragment extends BaseFragment {


    private CircleImageView fragmentImg;
    private TextView fragmentName;
    private TextView myOrder;
    private TextView myDizhi;
    private TextView noPay;
    private TextView myPj;

    @Override
    public int beanLayout() {
        return R.layout.fragment_my;
    }

    @Override
    public void initView() {

        fragmentImg = (CircleImageView) findViewById(R.id.fragment_img);
        fragmentName = (TextView) findViewById(R.id.fragment_name);
        myOrder = (TextView) findViewById(R.id.my_order);
        myDizhi = (TextView) findViewById(R.id.my_dizhi);
        noPay = (TextView) findViewById(R.id.no_pay);
        myPj = (TextView) findViewById(R.id.my_pj);
    }

    @Override
    public void initData() {

        //登录
        log();


        //我的地址
        mydizhi();

        //我的支付订单
        myorder();

        //我的未支付订单
        mynoorder();

        //评价页面
        goPj();

    }

    private void goPj() {
        myPj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), PjActivity.class);
                startActivity(intent);
            }
        });
    }

    private void mynoorder() {
        noPay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), NoPayActivity.class);
                startActivity(intent);
            }
        });
    }

    private void mydizhi() {
        myDizhi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ARouter.getInstance().build(RouterPath.AddressDiZhi.ADDRESSDIZHI)
                        .navigation();
            }
        });
    }

    private void myorder() {
        myOrder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), MyOrderActivity.class);
                startActivity(intent);
            }
        });
    }

    private void log() {
        EventBus.getDefault().register(this);
        fragmentImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ARouter.getInstance().build(RouterPath.Log.LOG)
                        .navigation();
            }
        });
    }

    @Subscribe
    public void Evevt(String event) {
        if (event.equals("golog")) {
            GlideUtil.getInstance().LoadImage(getContext(), R.drawable.xin, fragmentImg);
            fragmentName.setText("游客");
        }
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}